<?php
$urls = file("download.dat");
include_once "function.php";
$i=0;
$fileInfo =  pathinfo($_SERVER['SCRIPT_FILENAME']);
foreach($urls as $url) {
	if($i>100) {
		continue;
	}
	$i++;
	$name = trim(basename($url));
	echo $name."<br />";
	$urlArr = parse_url($url);
	$url = $urlArr['scheme']."://".$urlArr['host'].trim($urlArr['path'],"_");
	$ret = download($url);
	//echo $url."<br />";
	//$ret = file_get_contents($url);
	echo $fileInfo['dirname']."/".$name."<br />";
	$fp = fopen($fileInfo['dirname']."/".$name.".gif","x");
	if(!$fp) {
		echo "!!!Can not Open File!!!";
	}
	echo fwrite($fp,$ret);
}
?>